<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button id="A">发起成功请求</button>
    <button id="B">发起失败请求</button>
    <p id = 'D' style="font-size:60px; color:skyblue"></p>
    <!-- <script src="./03.Promise基本用法.js"></script> -->
    <script src="./demo.js"></script>

    <script>
        const btn1 = document.querySelector('#A')
        const btn2 = document.querySelector('#B')
        btn1.addEventListener('click', async function () {
            // const res = await myAjax({method:'GET',url:'http://ajax-base-api-t.itheima.net/api/getbooks'})
            // const {data} =res
            // data.forEach(item => console.log(item))
            
            Promise.all([
            myAjax({method:'GET', url:'http://ajax-base-api-t.itheima.net/api/getbooks'}),
            myAjax({method:'POST',data:{bookname:'挪威的森林',author:'村上春树',publisher:'上海出版社'}, url:'http://ajax-base-api-t.itheima.net/api/addbook'}),
            ]).then(res=>{
                document.querySelector('#D').innerHTML = '我是首页'
                // const [{data}] =res
                // data.forEach(item => console.log(item))
            }).catch(err=>{
               document.querySelector('#D').innerHTML = err
            })
        })
        btn2.addEventListener('click', async function () {
            // const res = await myAjax({method:'GET',url:'http://ajax-base-api-t.itheima.net/api/getbooks'})
            // const {data} =res
            // data.forEach(item => console.log(item))
            
            Promise.all([
            myAjax({method:'GET', url:'http://ajax-base-api-t.itheima.net/api/getbooks'}),
            myAjax({method:'POST',data:{bookname:'挪威的森林',author:'村上春树',publisher:'上海出版社'}, url:'http://ajax-base-api-t.itheima.net/api/addboo'}),
            ]).then(res=>{
                document.querySelector('#D').innerHTML = '我是首页'
                // const [{data}] =res
                // data.forEach(item => console.log(item))
            }).catch(err=>{
               document.querySelector('#D').innerHTML = err
            })
        })
    </script>
</body>

</html>